<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日志列表页</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_list.css">
</head>
<body>
<div class="nav">
    <img src="img/Personal_blog.png" alt="">
    <span class="title">个人博客</span>
    <span class="spacer"></span>
    <a href="blog_list.html">主页</a>
    <a href="blog-edit.html">写博客</a>
    <a href="loginOut">注销</a>
</div>
<div class="container">
    <div class="container-left">
        <div class="card">
            <img src="img/head_sculpture.jpg" class="avtar" alt="">
            <h3>负责人:</h3>
            <h2 class="userName"></h2>
            <div class="contact1">联系方式</div>
            <div class="contact2"></div>
            <div class="counter">
                <span>文章： </span>
                <span class="blogCount"></span>
            </div>
        </div>
    </div>
    <div class="container-right">


    </div>
</div>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="js/app.js"></script>
<script>
    function getBlogs(){
        $.ajax({
            type:"get",
            url:"blog",
            success:function(body){
                let container=document.querySelector('.container-right');
                for(let blog of body){
                    let blogDiv=document.createElement('div');
                    blogDiv.className="blog";
                    let titleDiv=document.createElement('div');
                    titleDiv.className="title";
                    let dateDiv=document.createElement('div');
                    dateDiv.className="date";
                    let descDiv=document.createElement('desc');
                    descDiv.className="desc";
                    let a=document.createElement('a');
                    a.className="detail";
                    titleDiv.innerHTML=blog.title;
                    dateDiv.innerHTML=blog.postTime;
                    let content=blog.content;
                    if(content.length>=100){
                        content=content.substring(0,100)+"...";
                    }
                    descDiv.innerHTML=content;
                    a.href="blog_content.html?blogId="+blog.blogId;
                    a.innerHTML="查看全文 &gt;&gt;";
                    blogDiv.appendChild(titleDiv);
                    blogDiv.appendChild(dateDiv);
                    blogDiv.appendChild(descDiv);
                    blogDiv.appendChild(a);
                    container.appendChild(blogDiv);
                }
            }
        });
    }
    function getUserInfo(){
        $.ajax({
           type: "get",
           url: "userInfo",
            success:function (body){
                console.log(body);
                let userName=document.querySelector(".container-left>.card>.userName");
                userName.innerHTML=body.userName;
                let contact=document.querySelector(".container-left>.card>.contact2");
                contact.innerHTML=body.contact;
                let blogCount=document.querySelector(".container-left>.card>.counter>.blogCount");
                blogCount.innerHTML=body.blogCount;

            }
        });
    }
    getBlogs();
    getUserInfo();
    getLogin();
</script>
</body>
</html>